package com.ruoyi.chiwen.controller;

import java.util.List;

import com.ruoyi.chiwen.domain.TbActormoney;
import com.ruoyi.chiwen.service.ITbActormoneyService;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.chiwen.domain.TbActor;
import com.ruoyi.chiwen.service.ITbActorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主播收益Controller
 * 
 * @author ruoyi
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/chiwen/actor")
public class TbActorController extends BaseController
{
    @Autowired
    private ITbActorService tbActorService;
    @Autowired
    private TokenService tokenService;

    @Autowired
    private ITbActormoneyService tbActormoneyService;


    /**
     * 查询主播收益详情列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:list')")
    @GetMapping("/actormoneylist")
    public TableDataInfo list(TbActormoney tbActormoney)
    {
        startPage();
        List<TbActormoney> list = tbActormoneyService.selectTbActormoneyList(tbActormoney);
        return getDataTable(list);
    }

    /**
     * 查询主播收益列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbActor tbActor)
    {
        startPage();

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        System.out.println(loginUser.getUser().getRemark());
        String chinal=loginUser.getUser().getRemark();
        tbActor.setChannel(chinal);
        List<TbActor> list = tbActorService.selectTbActorList(tbActor);
        return getDataTable(list);
    }

    /**
     * 导出主播收益列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:export')")
    @Log(title = "主播收益", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbActor tbActor)
    {
        List<TbActor> list = tbActorService.selectTbActorList(tbActor);
        ExcelUtil<TbActor> util = new ExcelUtil<TbActor>(TbActor.class);
        return util.exportExcel(list, "主播收益数据");
    }

    /**
     * 获取主播收益详细信息
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbActorService.selectTbActorById(id));
    }

    /**
     * 新增主播收益
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:add')")
    @Log(title = "主播收益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbActor tbActor)
    {
        return toAjax(tbActorService.insertTbActor(tbActor));
    }

    /**
     * 修改主播收益
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:edit')")
    @Log(title = "主播收益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbActor tbActor)
    {
        return toAjax(tbActorService.updateTbActor(tbActor));
    }

    /**
     * 删除主播收益
     */
    @PreAuthorize("@ss.hasPermi('chiwen:actor:remove')")
    @Log(title = "主播收益", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbActorService.deleteTbActorByIds(ids));
    }
}
